package com.chainshop.returns.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.chainshop.common.core.domain.pojo.ProductReturns;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chainshop.common.annotation.Log;
import com.chainshop.common.core.controller.BaseController;
import com.chainshop.common.core.domain.AjaxResult;
import com.chainshop.common.enums.BusinessType;
import com.chainshop.returns.service.IProductReturnsService;
import com.chainshop.common.utils.poi.ExcelUtil;
import com.chainshop.common.core.page.TableDataInfo;

/**
 * 店铺退货记录表Controller
 *
 * @author ruoyi
 * @date 2024-08-15
 */
@RestController
@RequestMapping("/sale/returns")
public class ProductReturnsController extends BaseController
{
    @Autowired
    private IProductReturnsService productReturnsService;

    /**
     * 查询店铺退货记录表列表
     */
    @PreAuthorize("@ss.hasPermi('sale:returns:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductReturns productReturns)
    {
        startPage();
        List<ProductReturns> list = productReturnsService.selectProductReturnsList(productReturns);
        return getDataTable(list);
    }

    /**
     * 导出店铺退货记录表列表
     */
    @PreAuthorize("@ss.hasPermi('sale:returns:export')")
    @Log(title = "店铺退货记录表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductReturns productReturns)
    {
        List<ProductReturns> list = productReturnsService.selectProductReturnsList(productReturns);
        ExcelUtil<ProductReturns> util = new ExcelUtil<ProductReturns>(ProductReturns.class);
        util.exportExcel(response, list, "店铺退货记录表数据");
    }

    /**
     * 获取店铺退货记录表详细信息
     */
    @PreAuthorize("@ss.hasPermi('sale:returns:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(productReturnsService.selectProductReturnsById(id));
    }

    /**
     * 新增店铺退货记录表
     */
    @PreAuthorize("@ss.hasPermi('sale:returns:add')")
    @Log(title = "店铺退货记录表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductReturns productReturns)
    {
        return toAjax(productReturnsService.insertProductReturns(productReturns));
    }

    /**
     * 修改店铺退货记录表
     */
    @PreAuthorize("@ss.hasPermi('sale:returns:edit')")
    @Log(title = "店铺退货记录表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductReturns productReturns)
    {
        return toAjax(productReturnsService.updateProductReturns(productReturns));
    }

    /**
     * 删除店铺退货记录表
     */
    @PreAuthorize("@ss.hasPermi('sale:returns:remove')")
    @Log(title = "店铺退货记录表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(productReturnsService.deleteProductReturnsByIds(ids));
    }
}
